<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<title>日报</title>
		<link rel="stylesheet"
			href="/resources/plugins/datatables/dataTables.bootstrap.css" />
		<style type="text/css">
.ui-datatable-scrollable-header-box {
	margin-left: 0px;
	margin-right: 15px !important;
}

iframe {
	width: 100%;
	height: 600px;
}

.ui-datalist-empty-message {
	/* height: 100px; */
	min-height: 100px;
}

.ui-datalist-content {
	/* height: 100px; */
	min-height: 100px;
	padding: 0px;
	margin: 0px;
	border: 0px;
}

.ui-widget .ui-widget {
	position: relative;
	left: 0px;
}
</style>
	</ui:define>
	<ui:define name="content">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button"
				styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button"
				styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<div id="headDiv" class="box box-solid with-border">
			<h:form id="headForm">
				<div class="box-header" id="queryDiv">
					<p:outputLabel for="popup5" value="日期：" />
					<p:calendar id="popup5" navigator="true"
						value="#{specialReportController.queryDate1}" pattern="yyyy-MM-dd"
						maxdate="Date()">
					</p:calendar>
					<p:outputLabel for="popup6" value="至 "
						style="margin-right:5px;margin-left:5px;" />
					<p:calendar id="popup6" navigator="true"
						value="#{specialReportController.queryDate2}" pattern="yyyy-MM-dd"
						maxdate="Date()">
					</p:calendar>
					<p:commandButton value="查询" id="query2"
						update="form:dataTb toolbar_s" icon="ui-icon-search"
						oncomplete="closeSelectDiv();"
						actionListener="#{specialReportController.queryByTime}"
						style="margin-left:5px;">
					</p:commandButton>
					<p:commandButton icon="ui-icon-refresh" value="重置"
						actionListener="#{specialReportController.resetQuery}"
						style="margin-left:5px;"
						update="popup5 popup6 toolbar_s form:dataTb "
						oncomplete="closeSelectDiv();" />
				</div>
				<div id="toolbarDiv">
					<p:toolbar id="toolbar_s">
						<f:facet name="left">
							<p:growl id="msgs" showDetail="true" />
							<p:commandButton id="cgBtn41" value="新建" icon="ui-icon-document"
								update="creatForm:createDetail2 creatForm:createSaveBtn2"
								actionListener="#{specialReportController.createReport}"
								oncomplete="PF('createDlg2').show();getTableScrollHeight();"
								rendered="#{s:hasPermission(session,'bhyx_bhrb_zxhb_xj')}" />
							<p:commandButton update="editForm:editDlgReport"
								oncomplete="PF('editDlgReport').show();getTableScrollHeight();"
								icon="ui-icon-pencil" value="编辑"
								rendered="#{s:hasPermission(session,'bhyx_bhrb_zxhb_bj')}"
								disabled="#{specialReportController.selectReport == null}">
							</p:commandButton>
							<p:commandButton value="删除" id="delbtn42" icon="ui-icon-trash"
								update="form:dataTb headForm:msgs toolbar_s"
								actionListener="#{specialReportController.deleteReport()}"
								disabled="#{specialReportController.selectReport == null}"
								rendered="#{s:hasPermission(session,'bhyx_bhrb_zxhb_sc')}"
								oncomplete="getTableScrollHeight();">
								<p:confirm header="提示" message="确定删除该记录吗?" icon="ui-icon-alert" />
							</p:commandButton>
						</f:facet>
					</p:toolbar>
				</div>
			</h:form>
		</div>
		<div id="infoDiv" class="box box-solid with-border">
			<h:form id="form">
				<p:dataTable id="dataTb" var="item"
					value="#{specialReportController.report}"
					selection="#{specialReportController.selectReport}"
					rowKey="#{item.id}" style="margin-bottom:0" emptyMessage="无记录"
					rows="10" paginator="true" rowsPerPageTemplate="10,20,50"
					paginatorPosition="bottom" rowIndexVar="ite"
					paginatorTemplate="{Customization} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					scrollable="true">
					<f:facet name="{Customization}">
						<p:outputLabel
							value="总计：#{specialReportController.report.size()} 条记录"
							style="margin-right:20px;"></p:outputLabel>
					</f:facet>
					<p:ajax event="rowSelectRadio"
						listener="#{specialReportController.ReportRowSelect}"
						update="headForm:toolbar_s editForm:editDlgReport"></p:ajax>
					<p:column selectionMode="single" width="10"
						style="text-align:center" />
					<p:column width="10" headerText="序号 ">
						<h:outputText value="#{ite+1}" />
					</p:column>
					<p:column width="60" headerText="专项类型 ">
						<h:outputText value="#{item.specialType}" />
					</p:column>
					<p:column width="140" headerText="专项内容">
						<h:outputText escape="false"
							value="#{specialReportController.replaceWithBr(item.specialContect)}" />
					</p:column>
					<p:column width="80" headerText="附件" selectRow="false">
						<p:rowExpansion>
							<p:repeat value="#{item.fileNames}" var="file"
								rendered="#{item.fileNames.size() != 0}">
								<div class="row" style="padding-left: 10px;">
									<p:commandLink title="删除"
										update="form:dataTb headForm:toolbar_s"
										style="margin-right:5px;float:left;"
										styleClass="ui-icon ui-icon-trash"
										rendered="#{s:hasPermission(session,'bhyx_bhrb_zxhb_wjsc')}"
										actionListener="#{specialReportController.removeFile(item.id,file)}">
										<p:confirm header="提示" message="确定删除该记录吗?"
											icon="ui-icon-alert" />
									</p:commandLink>
									<p:commandLink title="下载" oncomplete="downloadFunc()"
										styleClass="ui-icon ui-icon-arrowthick-1-s"
										rendered="#{s:hasPermission(session,'bhyx_bhrb_zxhb_wjxz')}"
										actionListener="#{specialReportController.fileDownloadView(file.id)}"
										style="margin-right:5px;float:left;"
										update="downloadForm:fileExist">
									</p:commandLink>
									<p:commandLink oncomplete="downloadFunc()"
										actionListener="#{specialReportController.fileDownloadView(file.id)}"
										style="word-break:break-all;margin-right:5px;float:left;"
										update="downloadForm headForm:toolbar_s">
										<span>#{file.description}</span>
									</p:commandLink>
								</div>
							</p:repeat>
							<p:repeat value="#{item.urlNames}" var="file"
								rendered="#{item.urlNames.size() != 0}">
								<div class="row" style="padding-left: 10px;">
									<p:commandLink title="删除" update=":form:dataTb"
										style="margin-right:5px;float:left;"
										styleClass="ui-icon ui-icon-trash"
										actionListener="#{specialReportController.removeFile(item,file.name)}">
										<p:confirm header="提示" message="确定删除该记录吗?"
											icon="ui-icon-alert" />
									</p:commandLink>
									<a href="#{file.url}"
										style="word-break: break-all; margin-right: 5px; float: left;"
										download="#{file.name}"> <span
										class="ui-icon ui-icon-arrowthick-1-s" /> <span>#{file.name}"</span>
									</a>
								</div>
							</p:repeat>
						</p:rowExpansion>
					</p:column>
					<p:column width="30" headerText="日期">
						<h:outputText value="#{item.day}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>
					</p:column>
					<p:column width="20" style="text-align: center">
						<p:commandButton update=":form:dataTb"
							actionListener="#{specialReportController.updateFile(item.id)}"
							title="上传附件" icon="ui-icon-arrowreturnthick-1-n"
							rendered="#{s:hasPermission(session,'bhyx_bhrb_zxhb_scwj')}">
							<p:ajax event="dialogReturn"
								listener="#{specialReportController.fileUploadReturn(item.id)}"
								update=":form:dataTb headForm:toolbar_s" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
				<p:dialog widgetVar="repeatDlg" id="repeatDlg" header="提示"
					modal="true" width="400">
					<p:outputLabel value="文件已存在，是否替换？" style="margin-left:30px;" />
					<p style="margin-left: 30px;">文件名称：</p>
					<p:dataList value="#{specialReportController.repeatFileNames}"
						var="fileName">
						#{fileName}
					</p:dataList>
					<p:commandButton
						actionListener="#{specialReportController.replaceFile}"
						oncomplete="PF('repeatDlg').hide()" update="dataTb" value="替换"
						style="margin-left:40px;" />
					<p:commandButton
						actionListener="#{specialReportController.cancelReplaceFile}"
						oncomplete="PF('repeatDlg').hide()" update="dataTb" value="撤销" />
				</p:dialog>
			</h:form>
			<h:form id="editForm">
				<p:dialog widgetVar="editDlgReport" id="editDlgReport" header="编辑"
					modal="true" width="800" height="300">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton value="保存" icon="ui-icon-disk"
								update="form:dataTb headForm:msgs"
								oncomplete="PF('editDlgReport').hide();getTableScrollHeight();"
								actionListener="#{specialReportController.update}" />
						</f:facet>
					</p:toolbar>
					<p:outputPanel style="width:100%;">
						<p:panelGrid style="width:100%;"
							rendered="#{not empty specialReportController.selectReport}">
							<p:row>
								<p:column>
									<h:outputLabel value="专项类型:" />
								</p:column>
								<p:column colspan="2">
									<p:inputText label="content"
										value="#{ specialReportController.selectReport.specialType}"
										required="true" requiredMessage="专项类型为必填项" style="width:100%;">
									</p:inputText>
								</p:column>
								<p:column>
									<h:outputLabel value="日期:" />
								</p:column>
								<p:column>
									<p:calendar value="#{specialReportController.selectReport.day}"
										pattern="yyyy-MM-dd" style="width:100%" navigator="true"
										maxdate="Date()" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputLabel value="专项内容:" />
								</p:column>
								<p:column colspan="4">
									<p:inputTextarea rows="8" label="content" autoResize="false"
										value="#{specialReportController.selectReport.specialContect}"
										style="width:100%;">
									</p:inputTextarea>
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:outputPanel>
				</p:dialog>
			</h:form>
			<h:form id="creatForm">
				<p:dialog widgetVar="createDlg2" header="新建" modal="true"
					id="createDlg2" width="800" height="300">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton id="createSaveBtn2" value="保存"
								update="form:dataTb headForm:msgs" icon="ui-icon-disk"
								oncomplete="PF('createDlg2').hide();getTableScrollHeight();"
								actionListener="#{specialReportController.saveNew}" />
						</f:facet>
					</p:toolbar>
					<p:outputPanel id="createDetail2" style="width:100%;">
						<p:panelGrid style="width:100%;"
							rendered="#{not empty specialReportController.created}">
							<p:row>
								<p:column>
									<h:outputLabel value="专项类型:" />
								</p:column>
								<p:column colspan="2">
									<p:inputText label="content"
										value="#{ specialReportController.created.specialType}"
										required="true" requiredMessage="专项类型为必填项" style="width:100%;">
									</p:inputText>
								</p:column>
								<p:column>
									<h:outputLabel value="日期:" />
								</p:column>
								<p:column>
									<p:calendar value="#{specialReportController.created.day}"
										pattern="yyyy-MM-dd" style="width:100%" navigator="true"
										maxdate="Date()" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputLabel value="专项内容:" />
								</p:column>
								<p:column colspan="4">
									<p:inputTextarea rows="8" label="content" autoResize="false"
										value="#{specialReportController.created.specialContect}"
										style="width:100%;">
									</p:inputTextarea>
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:outputPanel>
				</p:dialog>
			</h:form>
		</div>
		<!-- 为了在下载之前判断文件是否存在，所以将下载过程截开，用js判断存在后，再下载。若不存在，则弹出提示框。 -->
		<h:form id="downloadForm">
			<p:outputLabel style="display:none;" id="fileExist"
				value="#{specialReportController.fileExist}" />
			<p:commandButton ajax="false" id="downloadBtn" style="display:none;">
				<p:fileDownload value="#{specialReportController.file}" />
			</p:commandButton>
		</h:form>
	</ui:define>
	<ui:define name="contentend">
		<script>
			function downloadFunc() {
				debugger;
				var file = document.getElementById("downloadForm:fileExist");
				if (file.innerHTML == 'true') {
					document.getElementById("downloadForm:downloadBtn").click();
				} else {
					layer.msg('找不到文件！');
				}
			}
		</script>
		<script src="/resources/js/tables/singleScrollTable.js" />
	</ui:define>
</ui:composition>
